Expand description
A low-dimensional linear algebra library, targeted at computer graphics.
Trait overview
In order to make a clean, composable API, we divide operations into traits that are roughly based on mathematical properties. The main ones that we concern ourselves with are listed below:
VectorSpace
: Specifies the main operators for vectors, quaternions, and matrices.InnerSpace
: For types that have a dot (or inner) product - ie. vectors or quaternions. This also allows for the definition of operations that are based on the dot product, like finding the magnitude or normalizing.EuclideanSpace
: Points in euclidean space, with an associated space of displacement vectors.Matrix
: Common operations for matrices of arbitrary dimensions.SquareMatrix
: A special trait for matrices where the number of columns equal the number of rows.
Other traits are included for practical convenience, for example:
Array
: For contiguous, indexable arrays of elements, specifically vectors.ElementWise
: For element-wise addition, subtraction, multiplication, division, and remainder operations.
The prelude
Importing each trait individually can become a chore, so we provide a
prelude
module to allow you to import the main trait all at once. For
example:
use cgmath::prelude::*;
Modules
- Constrained conversion functions for assisting in situations where type inference is difficult.
- This module contains the most common traits used in
cgmath
. By glob-importing this module, you can avoid the need to import each trait individually, while still being selective about what types you import.
Macros
Structs
- A homogeneous transformation matrix.
- A two-dimensional rotation matrix.
- A three-dimensional rotation matrix.
- A generic transformation consisting of a rotation, displacement vector and scale amount.
- An angle, in degrees.
- A 2 x 2, column major matrix
- A 3 x 3, column major matrix
- A 4 x 4, column major matrix
- An orthographic projection with arbitrary left/right/bottom/top distances
- A perspective projection with arbitrary left/right/bottom/top distances
- A perspective projection based on a vertical field-of-view angle.
- A point in 2-dimensional space.
- A point in 3-dimensional space.
- A quaternion in scalar/vector form.
- An angle, in radians.
- A 2-dimensional vector.
- A 3-dimensional vector.
- A 4-dimensional vector.
Traits
- Angles and their associated trigonometric functions.
- An array containing elements of type
Element
- Base floating point types
- Base integer types
- Base numeric types with partial ordering
- Element-wise arithmetic operations. These are supplied for pragmatic reasons, but will usually fall outside of traditional algebraic properties.
- Points in a Euclidean space with an associated space of displacement vectors.
- A column-major matrix of arbitrary dimensions.
- Defines a multiplicative identity element for
Self
. - A trait providing a partial ordering.
- A trait for a generic rotation. A rotation is a transformation that creates a circular motion, and preserves at least one point in the space.
- A two-dimensional rotation.
- A three-dimensional rotation.
- A column-major major matrix where the rows and column vectors are of the same dimensions.
- A trait representing an affine transformation that can be applied to points or vectors. An affine transformation is one which
- Vectors that can be added together and multiplied by scalars.
- Defines an additive identity element for
Self
.
Functions
- Create a new angle, in degrees
- Dot product of two vectors.
- Create a perspective matrix from a view frustrum.
- Returns the multiplicative identity,
1
. - Create an orthographic projection matrix.
- Create a perspective projection matrix.
- Create a new angle, in radians
- The short constructor.
- The short constructor.
- The short constructor.
- Returns the additive identity,
0
.